﻿@model PagedList<ADZ_GoodsTempFileSupplier>
@{
    ViewBag.Title = "供应商自助批量上传物料列表";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    MoreTempProductQueryModel paramModel = new MoreTempProductQueryModel();
    if (ViewBag.paramModel != null)
    {
        paramModel = (MoreTempProductQueryModel)ViewBag.paramModel;
    }
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
    var supplier_id = ConvertHelper.ConvertTo<long>(ViewBag.supplier_id, 0);
}
<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("SupplierMoreTempProductList", "TempProduct")" method="get">
    <div class="form_query">
        <div>
            操作序号：
            <input type="text" name="batch" id="batch" class="abc input-default" placeholder="" value="@paramModel.Batch">&nbsp;
        </div>
        @if (supplier_id == 0)
        {
    <div>
        <info style="float:left;">供应商：&nbsp;</info>
        <div id="supplier_id_name"></div>&nbsp;
        <script>
                BUI.use('bui/select', function (Select) {
                    $.post('@Url.Action("getsuppliers", "common")', {  }, function (result) {
                        var suggest = new Select.Suggest({
                            render: '#supplier_id_name',
                            name: 'supplier_id_name',
                            data: result
                        });
                        suggest.render();
                        $("input[name='supplier_id_name']").val('@paramModel.supplier_id_name');
                        $("input[name='supplier_id_name']").attr("autocomplete", "off");
                    });
                });
        </script>
    </div>
        }
        <div>
            文件名：
            <input type="text" name="FileName" id="FileName" class="abc input-default" placeholder="" value="@paramModel.FileName">&nbsp;
        </div><div>
            上传结果：
            <select id="up_status" name="up_status">
                <option value="-10" @(paramModel.up_status == -10 ? "selected" : "")>全部结果</option>
                <option value="2" @(paramModel.up_status == 2 ? "selected" : "")>已入库</option>
                <option value="1" @(paramModel.up_status == 1 ? "selected" : "")>上传成功</option>
                <option value="0" @(paramModel.up_status == 0 ? "selected" : "")>上传失败</option>
            </select>&nbsp;
        </div><div>
            上传时间：
            <input type="text" name="begTime" class="calendar calendar-time" id="begTime" value="@paramModel.begTime.ToString(1)"> - <input type="text" name="endTime" class="calendar calendar-time" id="endTime" value="@paramModel.endTime.ToString(1)">&nbsp;
        </div><div>
            @{Html.RenderPartial(Url.Content("~/Views/Common/PageSize.cshtml"), paramModel);}
        </div><div>
            <button type="submit" class="btn btn-primary">查询</button>&nbsp; &nbsp;
            @{

                if (supplier_id > 0)
                {
                    <button type="button" class="btn btn-success" id="additem" onclick="document.location='/TempProduct/SupplierAddMoreTempProduct'">批量添加</button>
                }
            }

        </div>
    </div>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            @*<th style="width:40px"><input type="checkbox" name="chkall" id="chkall" />全选</th>*@
            <th>操作序号</th>
            <th>供应商</th>
            <th>文件名</th>
            <th>上传时间</th>
            <th>状态</th>
            <th>备注</th>
            <th>操作</th>
            <th>下载</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                @*<td>
                        <input type="checkbox" name="cbx_last" value="@m.seq_id" />
                    </td>*@
                <td>@m.batch</td>
                <td>
                    @{
                        var supplier = dbcontext.ADZ_SupplierMaster.FirstOrDefault(t => t.supplier_id == m.supplier_id);
                        if (supplier != null)
                        {
                            <info>@supplier.supplier_name</info>
                        }
                    }
                </td>
                <td>@m.file_name</td>
                <td>@m.create_time</td>
                <td>
                    @switch (m.status)
                    {
                        case 0:
                            @:<div class="red">上传失败</div>
                            break;
                        case 1:
                            @:<div class="green">上传成功</div>
                            break;
                        case 2:
                            @:<div class="blue">已入库</div>
                            break;
                        case 3:
                            @:<div class="red">入库失败</div>
                            break;
                        default:
                            @:<div class="red">状态异常[@m.status]</div>
                            break;
                    }
                </td>
                <td width="300px">
                    <div class="longcontent" title="@m.remark">@m.remark</div>
                </td>
                <td>
                    @if (m.status != 2)
                    {
                        if (supplier_id > 0)
                        {
                            <a href="javascript:void(0);" onclick="deleteSupplierMoreTemp(@m.seq_id)">删除</a>
                        }
                    }
                    @if (m.status == 1)
                    {
                        if (supplier_id == 0)
                        {
                            <a href="javascript:void(0);" onclick="remarkSupplierMoreTemp(@m.seq_id)">标记为已入库</a>
                        }
                    }
                </td>
                <td>
                    <a href="@Path.Combine(ConfigHelper.AppSetting<string>("supplier_temp_dir", "~/upload/supplier").Replace("~",""),m.file_name)">下载</a>
                </td>
            </tr>
        }
    }
</table>
<div class="inline pull-left total">
    总行数：@ViewData["AllCount"]
</div>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>
<script>
    reloadHandler = function ()
    {
        window.location.reload();
    }
    function remarkSupplierMoreTemp(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该信息标记为已入库吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("remarkSupplierMoreTemp", "TempProduct")";
                      parameter = { id: id };
                      $.post(url, parameter, function (result) {
                          ShowActionResultForAll(result, reloadHandler, reloadHandler);
                      });
                      this.close();
                  }
              },
              {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                      this.close();
                  }
              }

            ]
        });
    }


    function deleteSupplierMoreTemp(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要删除该记录吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("deleteSupplierMoreTemp", "TempProduct")";
                      parameter = { id: id };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
              },
              {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                      this.close();
                  }
              }

            ]
        });
    }


    $(function () {
        $('#additem').on('click', function () {
            window.document.location.href = "@Url.Action("SupplierAddMoreTempProduct", "TempProduct")";
        });
    });

</script>